﻿<!DOCTYPE HTML>
<html  xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/extras/spring-security">
<head th:include="_meta :: header">
<meta charset="utf-8"/>
<title>角色管理</title>
</head>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 权限配置 <span class="c-gray en">&gt;</span> 角色管理 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container">
<form action="#" th:action="@{/role}"  method="post">
	<div class="cl pd-5 bg-1 bk-gray"> <span class="l"> 
		<a sec:authorize="hasAuthority('/role/delete')" href="javascript:;" th:onclick="'javascript:deleteAll(\''+@{/role/delete}+'\')'"  class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a> 
		<a sec:authorize="hasAuthority('/role/add-role')" class="btn btn-primary radius" href="javascript:;" onclick="admin_role_add('添加角色','/role/add-role', '', '500')"><i class="Hui-iconfont">&#xe600;</i> 添加角色</a> 
	</span> 
	<span class="r">共有数据：<strong th:text="${pageInfo.total}"></strong> 条</span> </div>
	<table class="table table-border table-bordered table-hover table-bg">
		<thead>
			<tr>
				<th scope="col" colspan="6">角色管理</th>
			</tr>
			<tr class="text-c">
				<th width="25"><input type="checkbox" value="" name=""/></th>
				<th width="40">ID</th>
				<th width="200">角色名</th>
				<th>资源列表</th>
				<th width="300">描述</th>
				<th width="70">操作</th>
			</tr>
		</thead>
		<tbody>
		
		<tr  class="text-c" th:each="role:${pageInfo.list}">  
				<td><input type="checkbox" th:value="${role.id}" value="" name="id"/></td>
				<td th:text="${role.id}" ></td>
				<td th:text="${role.name}"></td>
				<td>
				<span th:each="resource:${role.resources}"><span th:text="${resource.name}"></span>&nbsp;&nbsp;</span>
				</td>
				<td th:text="${role.description}"></td>
				<td>
				<a title="编辑" sec:authorize="hasAuthority('/role/editor-role')" href="javascript:;" th:onclick="'javascript:admin_role_edit(\'角色编辑\',\''+@{/role/editor-role/}+${role.id}+'\',\'1\',\'\',\'510\')'" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6df;</i></a> 
				<a title="删除" sec:authorize="hasAuthority('/role/delete')" href="javascript:;"  th:onclick="'javascript:admin_role_del(\''+${role.id}+'\',\''+@{/role/delete}+'\')'" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i></a></td>
		</tr>
		</tbody>
	</table>
	<div th:include="_pagination :: page"></div>
	</form>
</div>
<!--_footer 作为公共模版分离出去-->
<div th:replace="_footer :: footerjs">
</div>

<script type="text/javascript">
/*管理员-角色-添加*/
function admin_role_add(title,url,w,h){
	layer_show(title,url,w,h);
}
/*管理员-角色-编辑*/
function admin_role_edit(title,url,id,w,h){
	layer_show(title,url,w,h);
}
/*管理员-权限-删除*/
function admin_role_del(id,url){
	layer.confirm('确认要删除吗？',function(index){
		var _list = new Array();
		_list[0] = id;
		$.ajax({
			type: 'POST',
			url: url,
			data:JSON.stringify(_list),  
   	        type:'post',  
   	        cache:false,  
   	        dataType:'json', 
   	        contentType:"application/json",  //发送信息至服务器时内容编码类型。
			success: function(data){
				//$(obj).parents("tr").remove();
				if(data){
					window.location.reload();
				}else{
					layer.msg('删除失败!',{icon:1,time:1000});
					//window.location.reload();
				}
				
			},
			error:function(data) {
				console.log("资源访问失败");
			},
		});		
	});
}
/*<![CDATA[*/
/*批量删除*/
function deleteAll(url){
	var _list = new Array();
	$('input[name="id"]:checked').each(
            function (i) {
                _list[i] = $(this).val();
            });
	
	if(_list.length <=0){
		layer.msg("请选择删除的角色");
		return false;
	}
    layer.confirm('确定要删除选中的全部数据吗？', {
		btn : [ '确定', '取消' ]
	// 按钮
	}, function() {
		 $.ajax({  
	   	     url:url,// 跳转到 action  
	   	     data:JSON.stringify(_list),  
	   	     type:'post',  
	   	     cache:false,  
	   	     dataType:'json', 
	   	     contentType:"application/json",  //发送信息至服务器时内容编码类型。    
	   	     success:function(data) {  
	   	         if(data == 1){  
	   	            window.location.reload();  
	   	         }else{  
	   	        	layer.msg("删除失败");  
	   	         }  
	   	      },  
	   	      error : function() {  
	   	    	  layer.msg("异常！");  
	   	      }  
	        });
	}, function() {

	});
}
/*]]>*/
</script>
</body>
</html>